// 批改结果页面逻辑
const essayApi = require('../../api/essayApi');

Page({
  data: {
    id: '',
    result: null,
    loading: false
  },

  onLoad: function (options) {
    if (options.id) {
      this.setData({ id: options.id });
      this.getResult(options.id);
    }
  },
  
  // 获取批改结果
  getResult: function (id) {
    if (this.data.loading) return;
    
    this.setData({ loading: true });
    
    wx.showLoading({
      title: '加载中...',
      mask: true
    });
    
    essayApi.getCorrectionResult(id)
      .then(result => {
        this.setData({
          result: result
        });
      })
      .catch(err => {
        console.error('获取批改结果失败', err);
        wx.showToast({
          title: '获取结果失败',
          icon: 'none'
        });
      })
      .finally(() => {
        this.setData({ loading: false });
        wx.hideLoading();
      });
  },
  
  // 分享
  onShareAppMessage: function () {
    const { result } = this.data;
    
    return {
      title: `我的作文《${result?.title || '作文'}》获得了${result?.score || ''}分！`,
      path: `/pages/correction/correction?id=${this.data.id}`
    };
  }
}); 